import cv2
from pyzbar.pyzbar import decode
import numpy as np
class QRCodeScanner:
    def detect(self, frame):
        """ 解析二维码 """
        decoded_objects = decode(frame)
        qr_codes = []
        for obj in decoded_objects:
            qr_codes.append(obj.data.decode("utf-8"))
            # 在二维码周围画矩形框
            points = obj.polygon
            if len(points) == 4:
                pts = [(point.x, point.y) for point in points]
                cv2.polylines(frame, [np.array(pts, np.int32)], True, (0, 255, 0), 2)
        return qr_codes

